package com.example.lxj.archives.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.archives.entity.TbIdentifier;
import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.archives.service.ITbIdentifierService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 鉴定人Controller
 *
 * @author lxj
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/archives/identifier")
public class TbIdentifierController extends BaseController {
    @Autowired
    private ITbIdentifierService tbIdentifierService;

    /**
     * 查询鉴定人列表
     */
    @Permission(value = "archives:identifier:list")
    @GetMapping("/list")
    public TableDataInfo list(TbIdentifier tbIdentifier, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbIdentifier> list = tbIdentifierService.selectTbIdentifierList(tbIdentifier);
        return getDataTable(list);
    }

    /**
     * 获取鉴定人详细信息
     */
    @Permission(value = "archives:identifier:query")
    @GetMapping(value = "/{identifierId}")
    public AjaxRes getInfo(@PathVariable("identifierId") Long identifierId) {
        return success(tbIdentifierService.selectTbIdentifierByIdentifierId(identifierId));
    }

    /**
     * 新增鉴定人
     */
    @Permission(value = "archives:identifier:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbIdentifier tbIdentifier) {
        return toAjax(tbIdentifierService.insertTbIdentifier(tbIdentifier));
    }

    /**
     * 修改鉴定人
     */
    @Permission(value = "archives:identifier:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbIdentifier tbIdentifier) {
        return toAjax(tbIdentifierService.updateTbIdentifier(tbIdentifier));
    }

    /**
     * 删除鉴定人
     */
    @Permission(value = "archives:identifier:remove")
    @DeleteMapping("/{identifierId}")
    public AjaxRes remove(@PathVariable("identifierId") Long identifierId) {
        return toAjax(tbIdentifierService.deleteTbIdentifierByIdentifierId(identifierId));
    }
}
